/// 实名认证请求模型
class RealnameAuthRequest {
  final int userid;
  final String name;
  final String idCardNo;
  final String timestamp;

  RealnameAuthRequest({
    required this.userid,
    required this.name,
    required this.idCardNo,
    required this.timestamp,
  });

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'userid': userid,
      'name': name,
      'idCardNo': idCardNo,
      'timestamp': timestamp,
    };
  }

  /// 转换为API请求格式 (使用API文档中的实际字段名)
  Map<String, dynamic> toApiJson() {
    return {
      'userid': userid,
      'name': name,
      'id_card_no': idCardNo, // 注意这里使用API文档中的实际字段名
      'timestamp': timestamp,
    };
  }

  /// 从JSON创建实例
  factory RealnameAuthRequest.fromJson(Map<String, dynamic> json) {
    return RealnameAuthRequest(
      userid: json['userid'] ?? 0,
      name: json['name'] ?? '',
      idCardNo: json['idCardNo'] ?? json['id_card_no'] ?? '',
      timestamp: json['timestamp'] ?? '',
    );
  }

  @override
  String toString() {
    return 'RealnameAuthRequest(userid: $userid, name: $name, idCardNo: ${_maskIdCard(idCardNo)}, timestamp: $timestamp)';
  }

  /// 脱敏显示身份证号
  String _maskIdCard(String idCard) {
    if (idCard.length < 8) return idCard;
    return idCard.replaceRange(6, idCard.length - 4, '****');
  }
}